﻿Public Class frmTracks

    Private _drive As Integer

    Public Sub New(drive As Integer)
        InitializeComponent()

        _drive = drive

    End Sub

    Private Sub frmTracks_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.Icon = My.Resources.Main

        For i = 1 To AddOn.Cd.BassCd.BASS_CD_GetTracks(_drive)
            lstTracks.Items.Add($"Track {i}")
        Next

    End Sub

    Private Sub lstTracks_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lstTracks.SelectedIndexChanged
        cmdUp.Enabled = lstTracks.SelectedItems.Count = 1
        cmdDown.Enabled = lstTracks.SelectedItems.Count = 1
        cmdOK.Enabled = lstTracks.SelectedItems.Count > 0

    End Sub

    Private Sub cmdUp_Click(sender As Object, e As EventArgs) Handles cmdUp.Click
        Dim index As Integer
        Dim item As Object

        index = lstTracks.SelectedIndex

        If index = 0 Then Exit Sub

        item = lstTracks.Items(index)
        With lstTracks
            .Items.RemoveAt(index)
            .Items.Insert(index - 1, item)
            .SelectedItem = item
        End With

    End Sub

    Private Sub cmdDown_Click(sender As Object, e As EventArgs) Handles cmdDown.Click
        Dim index As Integer
        Dim item As Object

        index = lstTracks.SelectedIndex

        If index = lstTracks.Items.Count - 1 Then Exit Sub

        item = lstTracks.Items(index)
        With lstTracks
            .Items.RemoveAt(index)
            .Items.Insert(index + 1, item)
            .SelectedItem = item
        End With

    End Sub

    Private Sub cmdOK_Click(sender As Object, e As EventArgs) Handles cmdOK.Click
        Me.Close()
    End Sub

    Private Sub cmdCancel_Click(sender As Object, e As EventArgs) Handles cmdCancel.Click
        Me.Close()
    End Sub

End Class